package com.punai.customer.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.customer.domain.CusMaterialCuItem;
import com.punai.customer.domain.contants.CusConstants;
import com.punai.customer.service.ICusMaterialCuItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 材料费用项Controller
 * 
 * @author zxw_
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/cus/cuMaterialItem")
public class CusMaterialCuItemController extends BaseController
{
    @Autowired
    private ICusMaterialCuItemService cusMaterialCuItemService;

    /**
     * 查询材料费用项列表
     */
    @PreAuthorize("@ss.hasPermi('materialItem:cuMaterialItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusMaterialCuItem cusMaterialCuItem)
    {
        startPage();
        List<CusMaterialCuItem> list = cusMaterialCuItemService.selectCusMaterialCuItemList(cusMaterialCuItem);
        return getDataTable(list);
    }

    /**
     * 获取材料费用项详细信息
     */
    @PreAuthorize("@ss.hasPermi('materialItem:cuMaterialItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cusMaterialCuItemService.selectCusMaterialCuItemById(id));
    }

    /**
     * 新增材料费用项
     */
    @PreAuthorize("@ss.hasPermi('materialItem:cuMaterialItem:add')")
    @Log(title = CusConstants.CL_NAME, businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CusMaterialCuItem cusMaterialCuItem)
    {
        return toAjax(cusMaterialCuItemService.insertCusMaterialCuItem(cusMaterialCuItem));
    }

    /**
     * 修改材料费用项
     */
    @PreAuthorize("@ss.hasPermi('materialItem:cuMaterialItem:edit')")
    @Log(title = CusConstants.CL_NAME, businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusMaterialCuItem cusMaterialCuItem)
    {
        return toAjax(cusMaterialCuItemService.updateCusMaterialCuItem(cusMaterialCuItem));
    }

    /**
     * 删除材料费用项
     */
    @PreAuthorize("@ss.hasPermi('materialItem:cuMaterialItem:remove')")
    @Log(title = CusConstants.CL_NAME, businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cusMaterialCuItemService.deleteCusMaterialCuItemByIds(ids));
    }
}
